<template>
  <div>
    <sort-bar>
      <template v-slot:left>
        <div class="rec-title">
          <img src="@/assets/img/index.png" />
          榜单
        </div>
      </template>
      <template v-slot:right>
        <div class="more" @click="topListClick">更多&nbsp;&gt;</div>
      </template>
    </sort-bar>
    <loader v-if="!list"></loader>
    <div class="rank-item">
      <div v-for="(item,number) in list" :key="item.index" class="rank-list">
        <div class="title" @click="toTopList(item.id)">
          <img :src="item.coverImgUrl" :alt="item.name" :title="item.name" />
          <div class="right">
            <p>{{item.name}}</p>
            <img src="@/assets/img/play.png" alt="play" title="播放" />
            <img src="@/assets/img/like.png" alt="like" title="收藏" />
          </div>
        </div>
        <loader v-if="!listTotal[number]"></loader>
        <ul v-else>
          <li
            v-for="(art,index) in listTotal[number]"
            :key="index"
            :class="{bgcolor: index%2 === 0}"
            @click="musicClick(art.id)"
          >
            <span class="text">
              <span>{{index+1}}</span>
              <span>{{art.name}}</span>
            </span>
            <span class="like">
              <img src="@/assets/img/like.png" alt="like" title="收藏" />
              <img src="@/assets/img/play.png" alt="play" title="播放" />
            </span>
          </li>
        </ul>
        <div class="more" @click="toTopList(item.id)">查看全部></div>
      </div>
    </div>
  </div>
</template>

<script>
import Loader from '@/components/common/loader/Loader'
import SortBar from "@/components/content/sortbar/SortBar";

export default {
  props: {
    list: {
      type: Array,
      default() {
        return []
      }
    },
    listTotal: {
      type: Array,
      default() {
        return []
      }
    }
  },
  components: {
    SortBar,
    Loader
  },
  methods: {
    // 跳转排行榜
    topListClick() {
      this.$router.push('/discover/toplist')
    },
    toTopList(id) {
      this.$router.push('/discover/toplist?id=' + id)
    },
    // 点击音乐跳转详情
    musicClick(songId) {
      this.$router.push('/discover/song/detail?id=' + songId)
    }
  }
};
</script>

<style scoped>
/* sortbar部分 */
.rec-title {
  display: flex;
  align-items: center;
}
.rec-title img {
  height: 14px;
  width: 14px;
  margin-right: 5px;
}

/* 榜单区域 */
.rank-item {
  margin-top: 30px;
  display: flex;
  border: 1px solid #000;
  background-color: #4f4f4f;
}

/* 每个榜单 */
.rank-list {
  flex: 1;
  border-right: 1px solid #999;
}
.rank-list:nth-child(3) {
  border: none;
}

/* 每个榜单头部 */
.title {
  display: flex;
  font-size: 14px;
  font-weight: 700;
  width: 100%;
  height: 80px;
  padding: 20px;
  margin-bottom: 20px;
}

.title img {
  cursor: pointer;
  width: 60px;
  height: 60px;
}

.right {
  margin: 10px 0 0 20px;
}
.right img {
  cursor: pointer;
  width: 25px;
  height: 25px;
  margin: 5px 0 0 10px;
}
.right p {
  cursor: pointer;
  color: #fff;
}

/* 排行榜部分 */
li {
  position: relative;
  color: #fff;
  height: 35px;
  line-height: 35px;
  padding: 0 20px;
  font-size: 14px;
  cursor: pointer;
}
.text {
  display: inline-block;
  width: 195px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text span:nth-child(1) {
  font-size: 16px;
  margin-right: 10px;
  color: #ff0000;
}

/* 鼠标进入时显示的图片 */
.like {
  position: absolute;
  right: 20px;
  bottom: -5px;
  display: none;
}
.like img {
  margin-left: 5px;
  width: 20px;
  height: 20px;
}
li:hover .text {
  width: 145px;
}
li:hover .like {
  display: block;
}

/* 查看全部 */
.more {
  cursor: pointer;
  font-size: 14px;
  height: 40px;
  line-height: 40px;
  padding: 0 10px;
  color: #fff;
  text-align: right;
}

/* 隔行不同颜色 */
.bgcolor {
  background-color: #3f3f3f;
}
</style>